source_id: &SourceId,
config: &Config)
-> CargoResult<(EitherManifest, Vec<PathBuf>)> {
- let project_root = manifest_file.parent().unwrap();
+ let package_root = manifest_file.parent().unwrap();
let toml = {
let pretty_filename =
let manifest = Rc::new(manifest);
return match TomlManifest::to_real_manifest(&manifest,
source_id,
- project_root,
+ package_root,
config) {
Ok((mut manifest, paths)) => {
for key in unused {
Err(e) => {
match TomlManifest::to_virtual_manifest(&manifest,
source_id,
- project_root,
+ package_root,
config) {
Ok((m, paths)) => Ok((EitherManifest::Virtual(m), paths)),
Err(..) => Err(e),
fn to_real_manifest(me: &Rc<TomlManifest>,
source_id: &SourceId,
- project_root: &Path,
+ package_root: &Path,
config: &Config)
-> CargoResult<(Manifest, Vec<PathBuf>)> {
let mut nested_paths = vec![];
CargoError::from("no `package` or `project` section found.")
})?;
- let project_name = project.name.trim();
- if project_name.is_empty() {
+ let package_name = project.name.trim();
+ if package_name.is_empty() {
bail!("package name cannot be an empty string.")
}
// If we have no lib at all, use the inferred lib if available
// If we have a lib with a path, we're done
// If we have a lib with no path, use the inferred lib or_else package name
- let targets = targets(me, project_name, project_root, &project.build)?;
+ let targets = targets(me, package_name, package_root, &project.build)?;
if targets.is_empty() {
debug!("manifest has no build targets");
}
- if let Err(e) = unique_build_targets(&targets, project_root) {
+ if let Err(e) = unique_build_targets(&targets, package_root) {
warnings.push(format!("file found to be present in multiple \
build targets: {}", e));
}
config: config,
warnings: &mut warnings,
platform: None,
- root: project_root,
+ root: package_root,
};
fn process_dependencies(
fn maybe_custom_build(&self,
build: &Option<StringOrBool>,
- project_dir: &Path)
+ package_root: &Path)
-> Option<PathBuf> {
- let build_rs = project_dir.join("build.rs");
+ let build_rs = package_root.join("build.rs");
match *build {
Some(StringOrBool::Bool(false)) => None, // explicitly no build script
Some(StringOrBool::Bool(true)) => Some(build_rs.into()),
/// Will check a list of build targets, and make sure the target names are unique within a vector.
/// If not, the name of the offending build target is returned.
-fn unique_build_targets(targets: &[Target], project_root: &Path) -> Result<(), String> {
+fn unique_build_targets(targets: &[Target], package_root: &Path) -> Result<(), String> {
let mut seen = HashSet::new();
- for v in targets.iter().map(|e| project_root.join(e.src_path())) {
+ for v in targets.iter().map(|e| package_root.join(e.src_path())) {
if !seen.insert(v.clone()) {
return Err(v.display().to_string());
}
pub fn targets(manifest: &TomlManifest,
- project_name: &str,
- project_root: &Path,
+ package_name: &str,
+ package_root: &Path,
custom_build: &Option<StringOrBool>)
-> CargoResult<Vec<Target>> {
- let layout = Layout::from_project_path(project_root);
+ let layout = Layout::from_package_path(package_root);
let lib = match manifest.lib {
Some(ref lib) => {
lib.validate_crate_type()?;
Some(
TomlTarget {
- name: lib.name.clone().or(Some(project_name.to_owned())),
+ name: lib.name.clone().or(Some(package_name.to_owned())),
path: lib.path.clone().or_else(
|| layout.lib.as_ref().map(|p| PathValue(p.clone()))
),
}
)
}
- None => inferred_lib_target(project_name, &layout),
+ None => inferred_lib_target(package_name, &layout),
};
let bins = match manifest.bin {
};
bins.clone()
}
- None => inferred_bin_targets(project_name, &layout)
+ None => inferred_bin_targets(package_name, &layout)
};
for bin in bins.iter() {
impl Layout {
/// Returns a new `Layout` for a given root path.
- /// The `root_path` represents the directory that contains the `Cargo.toml` file.
- fn from_project_path(root_path: &Path) -> Layout {
+ /// The `package_root` represents the directory that contains the `Cargo.toml` file.
+ fn from_package_path(package_root: &Path) -> Layout {
let mut lib = None;
let mut bins = vec![];
let mut examples = vec![];
let mut tests = vec![];
let mut benches = vec![];
- let lib_candidate = root_path.join("src").join("lib.rs");
+ let lib_candidate = package_root.join("src").join("lib.rs");
if fs::metadata(&lib_candidate).is_ok() {
lib = Some(lib_candidate);
}
- try_add_file(&mut bins, root_path.join("src").join("main.rs"));
- try_add_files(&mut bins, root_path.join("src").join("bin"));
- try_add_mains_from_dirs(&mut bins, root_path.join("src").join("bin"));
+ try_add_file(&mut bins, package_root.join("src").join("main.rs"));
+ try_add_files(&mut bins, package_root.join("src").join("bin"));
+ try_add_mains_from_dirs(&mut bins, package_root.join("src").join("bin"));
- try_add_files(&mut examples, root_path.join("examples"));
+ try_add_files(&mut examples, package_root.join("examples"));
- try_add_files(&mut tests, root_path.join("tests"));
- try_add_files(&mut benches, root_path.join("benches"));
+ try_add_files(&mut tests, package_root.join("tests"));
+ try_add_files(&mut benches, package_root.join("benches"));
return Layout {
- root: root_path.to_path_buf(),
+ root: package_root.to_path_buf(),
lib: lib,
bins: bins,
examples: examples,